package org.budo.maven.plugin.assembly.mojo;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.budo.maven.plugin.assembly.mojo.processor.BudoMavenAssemblySpringBootProcessor;

import lombok.Getter;
import lombok.Setter;

/**
 * maven 打包插件
 * 
 * @author lmw
 * @see org.apache.maven.plugins.dependency.fromConfiguration.UnpackMojo
 * @see org.apache.maven.plugins.assembly.mojos.SingleAssemblyMojo
 */
@Mojo( //
        name = "budo-assembly-spring-boot", //
        defaultPhase = LifecyclePhase.PACKAGE, //
        threadSafe = true, //
        requiresDependencyResolution = ResolutionScope.COMPILE //
)
@Getter
@Setter
public class BudoMavenAssemblySpringBootMojo extends AbstractMojo {
    @Parameter(defaultValue = "${project}", readonly = true, required = true)
    private MavenProject project;

    @Parameter(defaultValue = "${session}", readonly = true, required = true)
    private MavenSession session;

    @Parameter
    private String format = "tar"; // tar.gz tar zip

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        this.getLog().info("#44 BudoMavenAssemblySpringBootMojo#execute project.artifact=" + this.getProject().getArtifact() //
                + ", project.base=" + this.getProject().getBasedir() + ", format=" + this.getFormat() + ", this=" + this);

        try {
            new BudoMavenAssemblySpringBootProcessor(this.getProject(), this.getSession(), this.getFormat(), this.getLog()) //
                    .execute();
        } catch (Throwable e) {
            this.getLog().error("#88 doExecute error, e=" + e, e);
            throw new MojoExecutionException("#89 BudoMavenAssemblyMojo Error, e=" + e, e);
        }
    }
}